<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-col-xs6 layui-col-md4">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 100px;">
        <legend>图书检索</legend>
    </fieldset>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">搜索选项</label>
            <div class="layui-input-block">
                <select name="op" lay-filter="op">
                    <option value=""></option>
                    <option value="0" selected="">书名</option>
                    <option value="1">作者</option>
                    <option value="2">出版社</option>
                    <option value="3">出版年份</option>
                    <option value="4">ISBN</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">搜索内容</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入内容" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<div class="layui-col-xs12 layui-col-md8">
    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detail">详情</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="borrow">借阅与预约</a>
    </script>
</div>

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['table', 'miniPage', 'form'], function(){
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        form.render();
        table.render({
            elem: '#currentTableId',
            url: '/borrowerBooksInfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {field: 'id', title: '编号', sort: true},
                    {field: 'name',  title: '书名', sort: true},
                    {field: 'alias',  title: '别名', sort: true},
                    {field: 'author',title: '作者', sort: true},
                    {field: 'publishingHouse',  title: '出版社', sort: true},
                    {field: 'score', title: '评分', minWidth: 40, sort: true},
                    {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'

        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var content = miniPage.getHrefContent('/borrowerBooksDetail?id='+data.id);
                var index = layer.open({
                    title: data.name,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
                //layer.msg('ID：'+ data.id + ' 的查看操作');
            }else if (obj.event === 'borrow') {
                var content = miniPage.getHrefContent('/borrowBook?bookName='+data.name);
                var index = layer.open({
                    title: data.name,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%','100%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });
        form.on('submit(search)', function (data) {
            var op = data.field.op;
            var title = data.field.title;
            table.render({
                elem: '#currentTableId',
                url: '/borrowerBooksSearchDetail?op='+op+'&title='+title,
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [
                    [
                        {field: 'id', title: '编号', sort: true},
                        {field: 'name',  title: '书名', sort: true},
                        {field: 'alias',  title: '别名', sort: true},
                        {field: 'author', title: '作者', sort: true},
                        {field: 'publishingHouse', title: '出版社', sort: true},
                        {field: 'score', title: '评分', minWidth: 40, sort: true},
                        {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });
            return false;
        });
    });

</script>

</body>
</html>